<?php
class ControllerModuleOceanicThemeSettings extends Controller
{
	private $error = array();
	private $default = array(
		'status'		=> 0,

		'ots_showstore' => 0,

		'rts_layout'	=> 0,
		'rts_bg_texture'=> 'texture1.png',
		'rts_bg_color'	=> 'cceeff',
		'ots_topmenu'	=> '4d4d4d',
		'ots_topmenuh'	=> '66ccff',
		'rts_color1'	=> '66ccff',
		'rts_color2'	=> 'f2498f',
		'rts_f_header'	=> 'PT+Sans+Narrow',
		'rts_f_text'	=> 'Arial',
	);

	public function index()
	{
		$this->load->language('module/oceanic_theme_settings');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('setting/setting');

		$config = $this->config->get('oceanic_theme_settings_module');
		$config = (isset($config[0])) ? $config[0] : array();

		if(($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate())
		{
			$this->load->model('design/layout');
			$layouts = $this->model_design_layout->getLayouts();

			$pos = 0;
			$settings = array();

			foreach ($layouts as $layout) {
				$settings['oceanic_theme_settings_module'][$pos]['layout_id'] = $layout['layout_id'];
				$settings['oceanic_theme_settings_module'][$pos]['position'] = 'content_top';
				$settings['oceanic_theme_settings_module'][$pos]['sort_order'] = '';

				foreach($this->default as $key => $default_value)
				{                	if(isset($this->request->post[$key]))
					{
						$settings['oceanic_theme_settings_module'][$pos][$key] = $this->request->post[$key];
					}
					else if(isset($config[$key]))
					{
						$settings['oceanic_theme_settings_module'][$pos][$key] = $config[$key];
					}
					else
					{
		           		$settings['oceanic_theme_settings_module'][$pos][$key] = $default_value;
					}
				}

				$pos++;
			}

			$this->model_setting_setting->editSetting('oceanic_theme_settings', $settings);

			if(isset($this->request->get['client']) && $this->request->get['client'] == 'true')
			{
				echo '{"success":true}';
           		exit;
			}

			$this->session->data['success'] = $this->language->get('text_success');
			$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
		}

		/* languge data */
		$language_data = array(
			// Heading
			'heading_title',
			// Entry
			'entry_status',
			'entry_showinstore',
			'entry_showinstore_help',
			'entry_layout',
			'entry_bg_texture',
			'entry_bg_color',

			'entry_topmenu',
			'entry_topmenuhover',

			'entry_color1',
			'entry_color2',
			'entry_f_header',
			'entry_f_text',
			// Text
			'text_yes',
			'text_no',
			'text_module',
			'text_enabled',
			'text_disabled',
			'text_boxed',
			'text_fullwidth',
			// Other
			'text_success',
			'button_save',
			'button_cancel',
		);

		for($i = 0; $i < sizeof($language_data); $i++)
		{
        	$this->data[$language_data[$i]] = $this->language->get($language_data[$i]);
		}

		/* buttons */
		$this->data['action'] = $this->url->link('module/oceanic_theme_settings', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['token'] = $this->session->data['token'];

 		if(isset($this->error['warning']))
 		{
			$this->data['error_warning'] = $this->error['warning'];
		}
		else
		{
			$this->data['error_warning'] = '';
		}

		$this->data['textures'] = $this->getTextures();
		$this->data['fonts_header'] = $this->getFontsHeader();
        $this->data['fonts_text'] = $this->getFontsText();

  		$this->data['breadcrumbs'] = array();
   		$this->data['breadcrumbs'][] = array
   		(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);
   		$this->data['breadcrumbs'][] = array
   		(
       		'text'      => $this->language->get('text_module'),
			'href'      => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
   		$this->data['breadcrumbs'][] = array
   		(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('module/oceanic_theme_settings', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);

		$config = $this->config->get('oceanic_theme_settings_module');
		$config = (isset($config[0])) ? $config[0] : array();

		foreach($this->default as $key => $default_value)
		{
			if(isset($this->request->post[$key]))
			{
				$this->data[$key] = $this->request->post[$key];
			}
			else if(isset($config[$key]))
			{
				$this->data[$key] = $config[$key];
			}
			else
			{           		$this->data[$key] = $default_value;
			}
		}

		$this->template = 'module/oceanic_theme_settings.tpl';

		$this->children = array(
			'common/header',
			'common/footer',
		);

		$this->response->setOutput($this->render());
	}

	private function validate()
	{
		if(!$this->user->hasPermission('modify', 'module/oceanic_theme_settings'))
		{
			$this->error['warning'] = $this->language->get('error_permission');
		}

		if(!$this->error)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	private function getTextures()
	{		return array(
        	'texture1.png' => 'Texture 1',
			'texture2.jpg' => 'Texture 2',
			'texture3.png' => 'Texture 3',
			'texture4.png' => 'Texture 4',
			'texture5.png' => 'Texture 5',
			'texture6.png' => 'Texture 6',
			'texture7.png' => 'Texture 7',
			'texture8.png' => 'Texture 8',
			'texture9.png' => 'Texture 9',
			'texture10.png' => 'Texture 10',
			'texture11.png' => 'Texture 11',
			'texture12.png' => 'Texture 12',
			'texture13.png' => 'Texture 13',
			'texture14.png' => 'Texture 14',
			'texture15.png' => 'Texture 15',
			'texture16.png' => 'Texture 16',
		);
	}

	private function getFontsText()
	{
		return array(
			'Arial' => 'Arial',
			'Verdana' => 'Verdana',
			'Helvetica' => 'Helvetica',
			'Lucida Grande' => 'Lucida Grande',
			'Times New Roman' => 'Times New Roman',
			'Tahoma' => 'Tahoma',
			'Georgia' => 'Georgia',
		);
	}

	private function getFontsHeader()
	{		return array(
			'PT+Sans+Narrow' => 'PT Sans Narrow',
			'Aclonica' => 'Aclonica',
			'Actor' => 'Actor',
			'Advent+Pro' => 'Advent Pro',
			'Aldrich' => 'Aldrich',
			'Alegreya+SC' => 'Alegreya SC',
			'Allan' => 'Allan',
			'Allerta+Stencil' => 'Allerta Stencil',
			'Almendra+SC' => 'Almendra SC',
			'Amatic+SC' => 'Amatic SC',
			'Andada' => 'Andada',
			'Andika' => 'Andika',
			'Antic' => 'Antic',
			'Antic+Didone' => 'Antic Didone',
			'Antic+Slab' => 'Antic Slab',
			'Arapey' => 'Arapey',
			'Arbutus' => 'Arbutus',
			'Asul' => 'Asul',
			'Atomic+Age' => 'Atomic Age',
			'Aubrey' => 'Aubrey',
			'Audiowide' => 'Audiowide',
			'Average' => 'Average',
			'Averia+Gruesa+Libre' => 'Averia Gruesa Libre',
			'Averia+Libre' => 'Averia Libre',
			'Averia+Sans+Libre' => 'Averia Sans Libre',
			'Bangers' => 'Bangers',
			'Basic' => 'Basic',
			'Bentham' => 'Bentham',
			'Berkshire+Swash' => 'Berkshire Swash',
			'Bigshot+One' => 'Bigshot One',
			'Black+Ops+One' => 'Black Ops One',
			'Bonbon' => 'Bonbon',
			'Bowlby+One+SC' => 'Bowlby One SC',
			'Bree+Serif' => 'Bree Serif',
			'Bubblegum+Sans' => 'Bubblegum Sans',
			'Buenard' => 'Buenard',
			'Caesar+Dressing' => 'Caesar Dressing',
			'Calligraffitti' => 'Calligraffitti',
			'Cambo' => 'Cambo',
			'Cantarell' => 'Cantarell',
			'Cardo' => 'Cardo',
			'Carme' => 'Carme',
			'Caudex' => 'Caudex',
			'Ceviche+One' => 'Ceviche One',
			'Changa+One' => 'Changa One',
			'Chau+Philomene+One' => 'Chau Philomene One',
			'Chicle' => 'Chicle',
			'Coda+Caption' => 'Coda Caption',
			'Codystar' => 'Codystar',
			'Comfortaa' => 'Comfortaa',
			'Contrail+One' => 'Contrail One',
			'Convergence' => 'Convergence',
			'Copse' => 'Copse',
			'Coustard' => 'Coustard',
			'Covered+By+Your+Grace' => 'Covered By Your Grace',
			'Crafty+Girls' => 'Crafty Girls',
			'Crete+Round' => 'Crete Round',
			'Crushed' => 'Crushed',
			'Cuprum' => 'Cuprum',
			'Days+One' => 'Days One',
			'Delius+Swash+Caps' => 'Delius Swash Caps',
			'Doppio+One' => 'Doppio One',
			'Dorsa' => 'Dorsa',
			'Dosis' => 'Dosis',
			'Droid+Sans' => 'Droid Sans',
			'Dynalight' => 'Dynalight',
			'Eater' => 'Eater',
			'Economica' => 'Economica',
			'Electrolize' => 'Electrolize',
			'Emblema+One' => 'Emblema One',
			'Emilys+Candy' => 'Emilys Candy',
			'Enriqueta' => 'Enriqueta',
			'Euphoria+Script' => 'Euphoria Script',
			'Ewert' => 'Ewert',
			'Expletus+Sans' => 'Expletus Sans',
			'Fanwood+Text' => 'Fanwood Text',
			'Fascinate' => 'Fascinate',
			'Federo' => 'Federo',
			'Felipa' => 'Felipa',
			'Fjord+One' => 'Fjord One',
			'Flamenco' => 'Flamenco',
			'Flavors' => 'Flavors',
			'Fontdiner+Swanky' => 'Fontdiner Swanky',
			'Forum' => 'Forum',
			'Francois+One' => 'Francois One',
			'Fredericka+the+Great' => 'Fredericka the Great',
			'Frijole' => 'Frijole',
			'Galdeano' => 'Galdeano',
			'Gentium+Basic' => 'Gentium Basic',
			'Geo' => 'Geo',
			'Geostar' => 'Geostar',
			'Geostar+Fill' => 'Geostar Fill',
			'Germania+One' => 'Germania One',
			'Give+You+Glory' => 'Give You Glory',
			'Glass+Antiqua' => 'Glass Antiqua',
			'Glegoo' => 'Glegoo',
			'Gloria+Hallelujah' => 'Gloria Hallelujah',
			'Gochi+Hand' => 'Gochi Hand',
			'Gorditas' => 'Gorditas',
			'Great+Vibes' => 'Great Vibes',
			'Gudea' => 'Gudea',
			'Handlee' => 'Handlee',
			'Happy+Monkey' => 'Happy Monkey',
			'Henny+Penny' => 'Henny Penny',
			'Homenaje' => 'Homenaje',
			'Iceberg' => 'Iceberg',
			'Iceland' => 'Iceland',
			'IM+Fell+Double+Pica' => 'IM Fell Double Pica',
			'IM+Fell+DW+Pica+SC' => 'IM Fell DW Pica SC',
			'IM+Fell+English' => 'IM Fell English',
			'IM+Fell+French+Canon+SC' => 'IM Fell French Canon SC',
			'Inder' => 'Inder',
			'Inika' => 'Inika',
			'Irish+Grover' => 'Irish Grover',
			'Italiana' => 'Italiana',
			'Italianno' => 'Italianno',
			'Jim+Nightshade' => 'Jim Nightshade',
			'Jockey+One' => 'Jockey One',
			'Jolly+Lodger' => 'Jolly Lodger',
			'Josefin+Slab' => 'Josefin Slab',
			'Judson' => 'Judson',
			'Julee' => 'Julee',
			'Just+Another+Hand' => 'Just Another Hand',
			'Just+Me+Again+Down+Here' => 'Just Me Again Down Here',
			'Kameron' => 'Kameron',
			'Kelly+Slab' => 'Kelly Slab',
			'Kotta+One' => 'Kotta One',
			'Kreon' => 'Kreon',
			'Lancelot' => 'Lancelot',
			'Lato' => 'Lato',
			'Leckerli+One' => 'Leckerli One',
			'Lekton' => 'Lekton',
			'Limelight' => 'Limelight',
			'Lobster+Two' => 'Lobster Two',
			'Londrina+Sketch' => 'Londrina Sketch',
			'Love+Ya+Like+A+Sister' => 'Love Ya Like A Sister',
			'Loved+by+the+King' => 'Loved by the King',
			'Luckiest+Guy' => 'Luckiest Guy',
			'Lustria' => 'Lustria',
			'Macondo' => 'Macondo',
			'Macondo+Swash+Caps' => 'Macondo Swash Caps',
			'Magra' => 'Magra',
			'Mako' => 'Mako',
			'Marko+One' => 'Marko One',
			'Mate' => 'Mate',
			'Maven+Pro' => 'Maven Pro',
			'MedievalSharp' => 'MedievalSharp',
			'Medula+One' => 'Medula One',
			'Megrim' => 'Megrim',
			'Merienda+One' => 'Merienda One',
			'Merriweather' => 'Merriweather',
			'Metamorphous' => 'Metamorphous',
			'Michroma' => 'Michroma',
			'Miltonian' => 'Miltonian',
			'Miltonian+Tattoo' => 'Miltonian Tattoo',
			'Miniver' => 'Miniver',
			'Montaga' => 'Montaga',
			'Montez' => 'Montez',
			'Mr+Dafoe' => 'Mr Dafoe',
			'Mr+De+Haviland' => 'Mr De Haviland',
			'Mrs+Sheppards' => 'Mrs Sheppards',
			'Muli' => 'Muli',
			'Mystery+Quest' => 'Mystery Quest',
			'Niconne' => 'Niconne',
			'Nixie+One' => 'Nixie One',
			'Norican' => 'Norican',
			'Nosifer' => 'Nosifer',
			'Nothing+You+Could+Do' => 'Nothing You Could Do',
			'Nova+Flat' => 'Nova Flat',
			'Nova+Oval' => 'Nova Oval',
			'Nova+Round' => 'Nova Round',
			'Nova+Script' => 'Nova Script',
			'Nova+Slim' => 'Nova Slim',
			'Nova+Square' => 'Nova Square',
			'Numans' => 'Numans',
			'Nunito' => 'Nunito',
			'Oldenburg' => 'Oldenburg',
			'Oleo+Script' => 'Oleo Script',
			'Open+Sans+Condensed' => 'Open Sans Condensed',
			'Orbitron' => 'Orbitron',
			'Oswald' => 'Oswald',
			'Overlock' => 'Overlock',
			'Oxygen' => 'Oxygen',
			'Pacifico' => 'Pacifico',
			'Parisienne' => 'Parisienne',
			'Passero+One' => 'Passero One',
			'Philosopher' => 'Philosopher',
			'Pinyon+Script' => 'Pinyon Script',
			'Playball' => 'Playball',
			'Poly' => 'Poly',
			'Pompiere' => 'Pompiere',
			'Port+Lligat+Sans' => 'Port Lligat Sans',
			'Prata' => 'Prata',
			'Press+Start+2P' => 'Press Start 2P',
			'Prociono' => 'Prociono',
			'PT+Mono' => 'PT Mono',
			'PT+Sans' => 'PT Sans',
			'PT+Sans+Caption' => 'PT Sans Caption',
			'Quattrocento' => 'Quattrocento',
			'Radley' => 'Radley',
			'Rammetto+One' => 'Rammetto One',
			'Rancho' => 'Rancho',
			'Redressed' => 'Redressed',
			'Revalia' => 'Revalia',
			'Ribeye' => 'Ribeye',
			'Ribeye+Marrow' => 'Ribeye Marrow',
			'Ropa+Sans' => 'Ropa Sans',
			'Rosarivo' => 'Rosarivo',
			'Ruge+Boogie' => 'Ruge Boogie',
			'Russo+One' => 'Russo One',
			'Sail' => 'Sail',
			'Salsa' => 'Salsa',
			'Sancreek' => 'Sancreek',
			'Satisfy' => 'Satisfy',
			'Seaweed+Script' => 'Seaweed Script',
			'Sevillana' => 'Sevillana',
			'Shojumaru' => 'Shojumaru',
			'Short+Stack' => 'Short Stack',
			'Sigmar+One' => 'Sigmar One',
			'Sirin+Stencil' => 'Sirin Stencil',
			'Six+Caps' => 'Six Caps',
			'Snippet' => 'Snippet',
			'Sonsie+One' => 'Sonsie One',
			'Sorts+Mill+Goudy' => 'Sorts Mill Goudy',
			'Special+Elite' => 'Special Elite',
			'Spicy+Rice' => 'Spicy Rice',
			'Squada+One' => 'Squada One',
			'Stardos+Stencil' => 'Stardos Stencil',
			'Stint+Ultra+Condensed' => 'Stint Ultra Condensed',
			'Stint+Ultra+Expanded' => 'Stint Ultra Expanded',
			'Supermercado+One' => 'Supermercado One',
			'Tenor+Sans' => 'Tenor Sans',
			'Tienne' => 'Tienne',
			'Trade+Winds' => 'Trade Winds',
			'Trocchi' => 'Trocchi',
			'Trochut' => 'Trochut',
			'Trykker' => 'Trykker',
			'Tulpen+One' => 'Tulpen One',
			'Ubuntu+Mono' => 'Ubuntu Mono',
			'Uncial+Antiqua' => 'Uncial Antiqua',
			'UnifrakturCook' => 'UnifrakturCook',
			'UnifrakturMaguntia' => 'UnifrakturMaguntia',
			'Unkempt' => 'Unkempt',
			'Varela' => 'Varela',
			'Vibur' => 'Vibur',
			'Vidaloka' => 'Vidaloka',
			'Voces' => 'Voces',
			'Vollkorn' => 'Vollkorn',
			'Yellowtail' => 'Yellowtail',
			'Yesteryear' => 'Yesteryear',
		);
	}
}
?>